/*
--- dp
dp[i][j][k] = 最多赢的次数
1<=i<=1e5 前i轮游戏
1<=j<=3 当前手势
1<=k<=20 变化的次数

dp[i][1][k] = max(dp[i-1][1][k], dp[i][2][k-1], dp[i][3][k-1])  + iswin

dp[i][1][0] = dp[i-1][1][0] +iswin

--- 搜索
def dfs(i,j,k):
    if vis[i][j][k]:
        return vis[i][j][k]
    if i==0:
        return 0
    if k==0:
        dfs(i-1,j,0) + iswin
    for j in 不是现在用的手势:
        vis[i][j][k] = max(
            imp! vis[i][j][k],
            dfs(i-1,现在的手势,k), dfs(i-1,j,k-1)
        )+iswin
    return vis[i][j][k]

ans = max(
    dfs(n,1,k)
    dfs(n,2,k)
    dfs(n,3,k)
)
*/

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <vector>

using ll = int64_t;
ll n,k;
std::vector<std::vector<std::vector<ll>>> vis;
std::vector<ll> v;

static inline bool iswin(const ll a,const ll b){
    const ll tmp = a-b;
    return tmp==-1 || tmp==2;
}

static inline ll dfs(ll i,ll j,ll k){
    if(vis[i][j][k])return vis[i][j][k];
    if(i==0)return 0;
    if(k==0){
        return vis[i][j][k] = dfs(i-1,j,0)+iswin(j, v[i]);
    }
    vis[i][j][k] = dfs(i-1,j,k)+iswin(j, v[i]);
    for(ll nj=1;nj<=3;nj++){
        if(nj==j)continue;
        vis[i][j][k]=std::max(
            vis[i][j][k],
            dfs(i-1,nj,k-1)+iswin(j, v[i])
        );
    }
    return vis[i][j][k];
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n>>k;
    vis.resize(n+1,std::vector<std::vector<ll>>(3+1,std::vector<ll>(k+1)));
    v.resize(n+1);
    for(ll i=1;i<=n;i++){
        char tmp;
        std::cin>>tmp;
        if(tmp=='H'){
            v[i]=1;
        }else if(tmp=='S'){
            v[i]=2;
        }else{
            v[i]=3;
        }
    }
    ll ans=0;
    for(ll j=1;j<=3;j++){
        for(ll nk=0;nk<=k;nk++){
            ans=std::max(
                ans,
                dfs(n,j,nk)
            );
        }
    }
    std::cout<<ans<<"\n";
}